<template>
  <div>
    <!-- 头部组件 -->
    <my-head></my-head>
    <div class="box-img"><img src="../../assets/images/us1.jpg" alt="" /></div>
    <!-- 服务项目 -->

    <div class="bj">
      <xtltie :xtitle="xtitle"></xtltie>
      <div class="news-mian">
        <div
          :class="{ checked: newBtnId == item.id }"
          @click="changeNews(item.id)"
          v-for="item in newsBtn"
          :key="item.id"
        >
          {{ item.name }}
        </div>
      </div>
      <div class="content-list">
        <ul>
          <li v-for="item in newsList" :key="item.id">
            <div class="c-l-left">
              <img :src="item.cover" alt="" />
            </div>
            <div class="c-l-right">
              <h3>{{ item.title }}</h3>
              <div>
                <span
                  >发布时间：{{
                    new Date(Number(item.addTime) * 1000).toLocaleString()
                  }}</span
                >
                <span>浏览次数：{{ item.views }}次</span>
              </div>
              <p v-html="item.abstract"></p>
            </div>
          </li>
        </ul>
        <div class="pageNumber">
          <el-pagination
            :small="small"
            background
            @current-change="handleCurrentChange"
            @size-change="handleSizeChange"
            :current-page="Current"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            :layout="layout"
            :total="total"
          >
          </el-pagination>
        </div>
      </div>
      <!-- 底部导航 -->
      <bottom-nav></bottom-nav>
      <!-- <div class="nav-bot">
        <ul>
          <li>首页</li>
          <li>关于我们</li>
          <li>产品展示</li>
          <li>微短视频</li>
          <li>封坛/定制</li>
          <li>加盟网点</li>
          <li>新闻中心</li>
        </ul>
        <div>
          Copyright © 2018 Gxdanquan.cn All Rights Reserved 燕台山酒庄
          桂ICP备120XXXXXX号-4
        </div>
      </div> -->
    </div>
  </div>
</template>

<script>
import { getNewsList, getNewsClassList } from "../../api/goods.js";
import bottomNav from "../../components/bottomNav.vue";
//导入头部组件
import MyHead from "../../components/MyHead.vue";
//导入服务项目标题
import Xtltie from "../../components/Xtltie.vue";
export default {
  name: "News",
  //注册组件
  components: {
    MyHead,
    Xtltie,
    bottomNav,
  },
  data() {
    return {
      xtitle: {
        name: "新闻资讯",
        nameEnglish: "News information",
      },
      newsBtn: [], //新闻分类
      newBtnId: 0, //新闻分类按钮id
      newsList: [], //新闻列表
      Current: 1, //当前页
      total: 0, //总条数
      pageSize: 0, //每页大小
      layout: "total,sizes, prev, pager, next, jumper",
      small: false,
    };
  },
  mounted() {
    const viewPortWidth =
      window.innerWidth ||
      document.documentElement.clientWidth ||
      document.body.clientWidth;
    if (viewPortWidth < 750) {
      this.small = true;
      this.layout = "prev, pager, next";
    }
  },
  created() {
    this.newsClassListGet();
  },
  methods: {
    //获取新闻分类列表
    newsClassListGet() {
      getNewsClassList({ currentPage: 1, pageSize: 10 }).then((res) => {
        console.log("新闻分类", res.data.data);
        this.newsBtn = res.data.data.records;
        this.newBtnId = res.data.data.records[0].id;
        this.newsListGet(res.data.data.records[0].id);
      });
    },
    //获取新闻列表
    newsListGet(categoryId, currentPage = 1, pageSize=10) {
      getNewsList({ categoryId, currentPage, pageSize }).then((res) => {
        console.log("新闻", res.data.data);
        this.newsList = res.data.data.records;
        this.total = res.data.data.total;
        this.pageSize = res.data.data.size;
      });
    },
    //新闻分类按钮回调
    changeNews(id) {
      this.newBtnId = id;
      this.newsListGet(id);
    },
    //分页器页数变化时的回调
    handleCurrentChange(val) {
      this.Current = val;
      this.newsListGet(this.newBtnId, val);
    },
    //分页器页码大小改变
    handleSizeChange(val) {
      this.pageSize = val
      this.newsListGet(this.newBtnId, 1,val);
    },
  },
};
</script>

<style lang="less" scoped>
::v-deep {
  .el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: rgb(181, 0, 3);
    color: #fff;
  }
  .el-pagination.is-background .el-pager li.active {
    color: #fff;
    cursor: default;
  }
  .el-pagination.is-background .el-pager li:hover {
    color: rgb(181, 0, 3);
  }
  .el-pagination.is-background .el-pager li:not(.disabled):hover {
    color: rgb(181, 0, 3);
  }
  .el-pagination.is-background .el-pager li:not(.disabled).active:hover {
    background-color: rgb(181, 0, 3);
    color: #fff;
  }
  .el-select-dropdown__item.selected {
    color: rgb(181, 0, 3) !important;
  }
  .el-select .el-input.is-focus .el-input__inner {
    border-color: rgb(181, 0, 3) !important;
  }
  .el-pagination .el-select .el-input .el-input__inner:hover {
    border-color: rgb(181, 0, 3) !important;
  }
  .el-input.is-active .el-input__inner,
  .el-input__inner:focus {
    border-color: rgb(181, 0, 3) !important;
  }
}

@media screen and (min-width: 1029px) {
  .box-img {
    position: relative;
    margin-bottom: 80px;
    img {
      width: 100%;
    }
  }
  .bj {
    width: 100%;
    height: auto;
    padding-bottom: 50px;
    position: relative;
    background: url("../../assets/images/bbjj_02.jpg") center no-repeat;
    background-size: 100% 100%;
    .news-mian {
      margin-top: 70px;
      display: flex;
      justify-content: center;
      .checked {
        color: #ffffff;
        background-color: #b50003;
        pointer-events: none;
      }
      div {
        width: 128px;
        height: 40px;
        line-height: 40px;
        margin: 0 17px;
        border: 1px solid #f2f2f2;
        border-radius: 30px;
        background-color: #ffffff;
        &:hover {
          cursor: pointer;
        }
      }
    }
    .content-list {
      ul {
        width: 80%;
        margin: auto;
        padding-top: 40px;
        li {
          padding: 35px;
          margin-bottom: 25px;
          display: flex;
          border: 1px solid #f1f1f1;
          .c-l-right {
            width: 76%;
            margin-left: 10px;
            text-align: left;
            line-height: 29px;
            h3 {
              font-size: 20px;
              font-weight: bold;
              color: #444444;
            }
            div {
              font-size: 12px;
              color: #999999;
              span {
                margin-right: 10px;
              }
            }
            p {
              color: #444444;
            }
          }
          .c-l-right:hover {
            h3 {
              font-size: 20px;
              font-weight: bold;
              color: #b50003;
            }
            p {
              color: #b50003;
            }
          }
          .c-l-left {
            width: 30%;
            img {
              width: 100%;
            }
          }
        }
      }
    }
    .pageNumber {
      margin-top: 42px;
      span {
        padding: 10px;
        margin: 0 2px;
        border: 1px solid #f1f1f1;
      }
    }
    // 底部导航样式
    .nav-bot {
      margin-top: 65px;
      color: #000000;
      ul {
        display: flex;
        justify-content: center;
        li {
          font-size: 18px;

          margin: 20px 10px;
        }
      }
    }
  }
}
@media only screen and (min-width: 750px) and (max-width: 1028px) {
  .box-img {
    position: relative;
    margin-bottom: 30px;
    img {
      width: 100%;
    }
  }
  .bj {
    width: 100%;
    position: relative;
    background: url("../../assets/images/bbjj_02.jpg") center no-repeat;
    background-size: 100% 100%;
    .news-mian {
      margin-top: 30px;
      display: flex;
      justify-content: center;
      .checked {
        color: #ffffff;
        background-color: #b50003;
        pointer-events: none;
      }
      div {
        width: 80px;
        height: 25px;
        line-height: 25px;
        margin: 0 17px;
        font-size: 14px;
        border: 1px solid #f2f2f2;
        border-radius: 30px;
        background-color: #ffffff;
        &:hover {
          cursor: pointer;
        }
      }
    }
    .content-list {
      ul {
        width: 80%;
        margin: auto;
        padding-top: 40px;
        li {
          padding: 15px;
          margin-bottom: 25px;
          display: flex;
          border: 1px solid #f1f1f1;
          .c-l-right {
            width: 70%;
            margin-left: 10px;
            text-align: left;
            line-height: 20px;
            h3 {
              font-size: 16px;
              font-weight: bold;
              color: #444444;
            }
            div {
              font-size: 12px;
              color: #999999;
              span {
                margin-right: 10px;
              }
            }
            p {
              color: #444444;
              font-size: 12px;
              display: -webkit-box; //对象作为弹性伸缩盒子模型显示
              overflow: hidden; //溢出隐藏
              -webkit-box-orient: vertical; //设置伸缩盒子对象的子元素的排列方式
              -webkit-line-clamp: 3; //设置 块元素包含的文本行数
            }
          }
          .c-l-right:hover {
            h3 {
              font-weight: bold;
              color: #b50003;
            }
            p {
              color: #b50003;
            }
          }
          .c-l-left {
            width: 30%;
            img {
              width: 100%;
            }
          }
        }
      }
    }
    .pageNumber {
      margin-bottom: 22px;
      span {
        padding: 10px;
        margin: 0 2px;
        border: 1px solid #f1f1f1;
      }
    }
    // 底部导航样式
    .nav-bot {
      padding-bottom: 57px;
      color: #000000;
      ul {
        display: flex;
        justify-content: center;
        li {
          font-size: 16px;
          margin: 20px 10px;
        }
      }
    }
  }
}
@media screen and (max-width: 749px) {
  .box-img {
    position: relative;
    margin-bottom: 30px;
    img {
      width: 100%;
    }
  }
  .bj {
    width: 100%;
    position: relative;
    background: url("../../assets/images/bbjj_02.jpg") center no-repeat;
    background-size: 100% 100%;
    .news-mian {
      margin-top: 30px;
      display: flex;
      justify-content: center;
      .checked {
        color: #ffffff;
        background-color: #b50003;
      }
      div {
        width: 80px;
        height: 25px;
        line-height: 25px;
        margin: 0 17px;
        font-size: 14px;
        border: 1px solid #f2f2f2;
        border-radius: 30px;
        background-color: #ffffff;
        white-space: nowrap;
        padding: 0 3px;
      }
    }
    .content-list {
      ul {
        width: 99%;
        margin: auto;
        padding-top: 20px;
        li {
          padding: 5px;
          margin-bottom: 25px;
          display: flex;
          border: 1px solid #f1f1f1;
          .c-l-right {
            width: 65%;
            margin-left: 10px;
            text-align: left;
            line-height: 20px;
            h3 {
              font-size: 12px;
              font-weight: bold;
              color: #444444;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
            div {
              font-size: 12px;
              color: #999999;
              span {
                display: inline-block;
                margin-right: 10px;
              }
            }
            p {
              color: #444444;
              font-size: 12px;
              display: -webkit-box; //对象作为弹性伸缩盒子模型显示
              overflow: hidden; //溢出隐藏
              -webkit-box-orient: vertical; //设置伸缩盒子对象的子元素的排列方式
              -webkit-line-clamp: 2; //设置 块元素包含的文本行数
            }
          }
          .c-l-right:hover {
            h3 {
              font-weight: bold;
              color: #b50003;
            }
            p {
              color: #b50003;
            }
          }
          .c-l-left {
            width: 35%;
            img {
              width: 100%;
            }
          }
        }
      }
    }
    .pageNumber {
      font-size: 12px;
      margin-bottom: 22px;
      span {
        padding: 10px;
        margin: 0 2px;
        /*border: 1px solid #f1f1f1;*/
      }
    }
    // 底部导航样式
    .nav-bot {
      padding-bottom: 57px;
      color: #000000;
      ul {
        display: flex;
        justify-content: center;
        li {
          font-size: 16px;
          margin: 20px 10px;
        }
      }
    }
  }
}
</style>